Degrees Fahrenheit ($T_F$) are converted to degrees Celsius ($T_c$) using the formula:
$$ T_c = 5(T_f - 32)/9 $$Write a program to convert 78 degrees Fahrenheit to degrees Celsius and print the result. Write your program such that you can easily change the temperature in Fahrenheit that you are converting from.
In [1]:
T_fahrenheit = 80
T_celsius = 5 * (T_fahrenheit - 32) / 9
print('The temperature in degrees Celsius is {0:.2f}'.format(T_celsius))
Interest on a bank loan is charged at fixed rate above the Bank of England 'official Bank Rate'.
Write a program that computes the interest payable, using the following variables in your program:
Test your program with a loan principal of £150,000, bank rate of 0.25%, rate over the bank rate of 1.49% and a period of 28 days.
Modify your program such that it prompts the user to interactively enter the principal and the number of days.
Hint: To prompt a user to input numerical data, use the command:
# Get input from user
number = float(input('How many seconds in one minute? '))
Do not forget to use float
. The reason for this will be explained later.
In [2]:
# Initial values
#loan_principal = 150000
official_rate = 0.0025
rate_over = 0.0149
#days_period = 28
# Get input from user
loan_principal = float(input('What is your loan principal? '))
days_period = float(input('What is the period (in days) of your loan? '))
# Calculate the interest
interest = (loan_principal
* ((official_rate + rate_over) / 365) # daily interest rate
* days_period)
print('The interest on the loan is £{0:.2f}'.format(interest))